package logic

import (
	"context"
	"novel-hub/models/mysql"

	"novel-hub/novelrpc/internal/svc"
	"novel-hub/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ContentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewContentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContentListLogic {
	return &ContentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ContentListLogic) ContentList(in *novelrpc.ContentListRequest) (*novelrpc.ContentListResponse, error) {
	// todo: add your logic here and delete this line

	var content mysql.Content
	var lists []*novelrpc.ContentList
	var err error
	lists, err = content.ContentList(mysql.DB, in.Title, lists)
	if err != nil {
		return nil, err
	}

	return &novelrpc.ContentListResponse{
		List: lists,
	}, nil
}
